<#include "/macro.include"/>
<#assign className = table.className>
<#assign classNameLower = className?uncap_first>
<#include "/java_imports.include"/>

var ${className}list_URL = {
    FormPage : 'toFormPage.jhtml'
}

var ${className}list = function() {
    var func = {
        init:function() {
            func.bindAddButton();
            func.bindRemoveBlackButton();
            func.bindSubmitButton();
            func.bindResetButton();
            func.bindFormValidate();
        },
        bindAddButton:function() {
            $('#toFormPage').click(function(){
                window.location.href = ${className}list_URL.FormPage;
            })
        },
        bindRemoveBlackButton:function() {
            $('.deleteButton').click(function(){
                var id = $(this).attr("title");
                var temp = {};
                $.data(temp, 'id', id);
                BootstrapDialog.confirm({
                    message: "" + $.i18n.prop('petshop.message.delete') + "",
                    type: BootstrapDialog.TYPE_WARNING,
                    callback: function(result) {
                        if (result) {
                            Golbal.showBlock(""+ $.i18n.prop('petshop.message.golbal')+"");
                            var id = $.data(temp, 'id');
                            window.location.href="delete.jhtml?id=" + id;
                        }
                    }
                });
            });
        },
        bindSubmitButton:function(){
            $("#submitForm").click(function(){
                $('#putFormId').submit();
            });
        },
        bindResetButton:function(){
            $("#resetForm").click(function(){
                $('#putFormId')[0].reset();
            });
        },
        bindFormValidate:function() {
            $("#putFormId").validate({
                rules:{
                    name: {
                        required: true
                    },
                    age: {
                        required: true
                    }
                }
            });
        }
    }
    func.init();
};

$(document).ready(function() {
    new ${className}list();
});
